package org.jeecg.modules.strategy.component;

import org.jeecg.modules.strategy.mapper.WebsiteMetaMapper;
import org.jeecg.modules.strategy.model.entity.MetaEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

@Component
public class MetaPipeline implements Pipeline {
    private final WebsiteMetaMapper websiteMetaMapper;

    @Autowired
    public MetaPipeline(WebsiteMetaMapper websiteMetaMapper) {
        this.websiteMetaMapper = websiteMetaMapper;
    }

    @Transactional
    @Override
    public void process(ResultItems resultItems, Task task) {
        MetaEntity metaEntity = resultItems.get("metaEntity");
        if (metaEntity != null) {
            websiteMetaMapper.insert(metaEntity);
        }
    }
}
